/****************************************************************************
*
*  ALi (Shanghai) Corporation, All Rights Reserved. 2007 Copyright (C)
*
*  File: lib_mp.h
*
*  Description: This file contains APIs to AP for stb media player.
*              
*  History:
*      Date        	Author         	Version   		Comment
*      ====        	======      	=======   	=======
 *  1.  2007.5.22  Dukula_Zhu  	0.0.1  		
****************************************************************************/

#ifndef	__LIB_MP_H__
#define	__LIB_MP_H__

#include <types.h>
#include <sys_config.h>
#include <basic_types.h>
#include <api/libmp/pe.h>

//typedef unsigned long long UINT64;
typedef UINT8 UDISK_ID;

#define INVALID_UDISK_ID 0xFF

#define PLAYLIST_MAX_NUM	1000 //max item num in every playlist
#define PLAYLIST_FILE_ADD_ONCE //one valid file can only be added to playlist for one time

#ifdef MULTI_VOLUME_SUPPORT
#define MP3_ROOT_DIR "/mnt"
#else
#define MP3_ROOT_DIR "/c"
#endif

#define FILE_NAME_SIZE	1024//(260*2)	//name size, not include extension name
#define FILE_EXT_NAME_SIZE 5

#define IMAGE_ANGLE_MASK 0xF0
#define IMAGE_DIS_MODE_MASK 0x0F

typedef enum{
	STORAGE_TYPE_USB,
	STORAGE_TYPE_SD,
	STORAGE_TYPE_HDD,
	STORAGE_TYPE_SATA,
	
	
	STORAGE_TYPE_ALL
}StorageDeviceType;


//prime numbers between 0~255 means file type, and some of them multiply to be mediatype
//primes:	2	3	5	7	11	13	17	19	23	29	31	37	41	43	47	53	59	61
//67	71	73	79	83	89	97	101	103	139	149	151	157	163	167	173	179	181	191	193	197	199
//211	223	227	229	233	239	241	251

typedef enum{ 
	F_DIR=	0,
	F_UNKOWN=	1,
	F_BMP=	2,
	F_MP3=	3,
	F_JPG=	5,
	F_TXT=	7,
	F_BYE1=	11,
	F_OGG= 13,
	F_MPG = 17,
	F_MPEG = 19,
	F_MP4 = 23,
	F_FLC = 29,
	F_WAV = 31,
	F_PCM = 37,

	F_ALL=	255,
}file_type; //valid types arranged be alphabet

#define MIXED_FILELIST_SUPPORT //not diff music from picture, there is only one type filelist

#ifndef MEDIA_PLAYER_VIDEO_SUPPORT
    #define MP_TYPE_NUM 3 //mediatype that supported now
#else
    #define MP_TYPE_NUM 4
#endif

typedef enum{
	MP_MUSIC=	0,
	MP_PICTURE=	1,
#ifdef MEDIA_PLAYER_VIDEO_SUPPORT
	MP_VIDEO = 2,
	MP_MIXED =	3,
#else
	MP_MIXED = 2,
#endif

}mp_type;

typedef enum{
	UDS_IDEL=0,
	UDS_BUSY,
}udisk_state;

typedef enum{
	PLS_IDEL=0,
	PLS_MANAGEMENT,
	PLS_PLAY,
}playlist_state;
	
typedef enum{
	FS_NO=0,
	FS_FAT12,
	FS_FAT16,
	FS_FAT32,
	FS_NTFS,
}file_system;

typedef enum{
	PL_ALI_MUSIC=0,
	PL_ALI_PICTURE,	
	PL_WINAMP,
}playlist_format;	//maybe used when need to save playlist someday

typedef enum{
	SORT_RAND=0,
	SORT_NAME, 
	SORT_TYPE,
	SORT_NAME_A_Z,
	SORT_NAME_Z_A,
	SORT_TYPE_IMG_1ST,
	SORT_TYPE_MSC_1ST,
	SORT_DATE,
	SORT_SIZE,
}sort_type;

typedef enum{
	LP_RAND_LOOP=0,
	LP_ALL_LOOP,
	LP_ALL,
	LP_ONE_LOOP,
	LP_RAND,
	LP_ONE,
}loop_type;

typedef enum{
	ME_NO=0,
	ME_POP,
	ME_CLASSIC,
}effect_mode_music;

typedef enum{
	PE_NO=0,
	PE_LEFT_IN,
	PE_UP_IN,
}effect_mode_picture;

typedef enum{
	Bluse=0,
	ClassicRock,
}genre_type;

typedef struct{
	char	name[FILE_NAME_SIZE];
	char path[FILE_NAME_SIZE];
	file_type	filetype;
}file_info, *p_file_info;	//info for ui show

typedef struct{
	char			name[32];	//playlist name
	UINT16		playidx;	//which is playing now
	UINT16		playednum;	//num that has been played
	loop_type		looptype;
	UINT8		loopnum;
	UINT16		filenum;	
	UINT8		num_limit_enable; //if playlist is limited in num
	UINT8 		add_once;	//if support one file only be added once to playlist at one time
	UINT16		limit_num;
	sort_type		sorttype;
	UINT8		sortorder;
	UINT16		*looppicture;	//used for random play
	union{
		struct{
			effect_mode_music	effectmode;	//music effect type
			UINT8	resv;
			UINT8	showtitle;	//mp3 show style
			UINT8	showartist;
			UINT32	resv1;
		}msc;
		struct{
			UINT16	interval;
			UINT16	scalemode;
			char		*bkg_music;	//backgroud music
		}pic;
	}ext;
} playlist_info, *p_playlist_info;

typedef struct{
	char		title[30];	
	char		artist[30];
	char		album[30];
	char		year[4];
	char		comment[30];
	genre_type	genre;
	UINT8	track;
}fileinfo_id3v1, *p_fileinfo_id3v1;

typedef struct{
	UINT64	size;
	UINT32	time;	//total time
	UINT8	mpeg;	//version
	UINT8	layer;
	UINT8	isVBR;
	UINT32	bitrate;
	UINT32	offset;	//offset for first frame
	UINT32	framenum;
	UINT16	samplerate;	
	UINT8	stereo;
	UINT8	hasCRC;
	UINT8	isProtected;
	UINT8	isOrigin;
}fileinfo_mpeg, *p_fileinfo_mpeg;

typedef struct{
	fileinfo_id3v1	basicinfo;
	char		music[30];
	char		origin[30];
}fileinfo_id3v23, *p_fileinfo_id3v23;

typedef struct{
	char		title[30];	
	char		artist[30];
	char		album[30];
	char		year[4];
	UINT32	size;
	UINT32	time;	//total time
}fileinfo_mp3, *p_fileinfo_mp3;

typedef struct{
	UINT32	fsize;
	UINT32	width;
	UINT32	height;
	UINT32	bbp;
}fileinfo_picture, *p_fileinfo_picture;

/*
typedef struct{
}fileinfo_bmp, *p_fileinfo_bmp;
*/

typedef struct{
	UINT32	time;	//total time
	int		playtime;
	UINT8	isVBR;
	UINT32	bitrate;
	UINT16	samplerate;	
}playinfo_music, *p_playinfo_music;

typedef struct{
}playinfo_picture, *p_playinfo_picture;

typedef struct
{
	char VideoDec[10]; //the name of the video codec. For now, we support below video codec:
	                   //"mp43", "XIV1", "XIV2", "XVID", "unknown"
	char AudioDec[10]; //the name of the audio codec. For now, we support below audio codec:
	                   //"PCM", "MP3", "AC3", "DTS", "unknown"
	DWORD AudioStreamNum; //The audio track number in the media stream
	DWORD SubStreamNum; //The subtitle stream number in the media stream
	DWORD TotalFrameNum; //The total frame number of the media stream
	DWORD FramePeriod; //The frame period of the media stream
	DWORD TotalTime; //Total play time of the media stream
	int   width; //The width of the media stream. The maximum width the video decoder can support is 720.
	int   height; //The height of the media stream. The maximum height the video decoder can support is 576.
	DWORD VideoBitrate;
	DWORD AudioBitrate;
	DWORD AudioChannelNum;
	UINT32 fsize;
	INT32 AudioSampleRate;
	INT32 video_codec_tag;
	INT32 cur_audio_stream_id;
    INT32 cur_sub_stream_id;

	INT32 cur_prog_id;

	DWORD ProgNum;
    DWORD dwProgIndex;
	BYTE byCAFree;
	CHAR acProvideName[33];
	CHAR acProgName[33];
    DWORD dw_detail_flag;
}fileinfo_video, *p_fileinfo_video;



BOOL		udisk_check_playlist_available(mp_type type);
BOOL		udisk_check_openroot(mp_type type);
UINT8 		udisk_check_available(void);
udisk_state 	udisk_check_state(void);
file_system 	udisk_getinfo(UINT64 *size, UINT64 *free);	
UDISK_ID 	udisk_init(UDISK_ID id, mp_callback_func mp_cb, UINT32 buf_addr, UINT32 buf_len);
RET_CODE 	udisk_close(UDISK_ID idx);
RET_CODE 	udisk_chdir(UINT16 dirorder, mp_type type);
RET_CODE 	udisk_chgtoparentdir(mp_type type);
RET_CODE 	udisk_chgtorootdir(mp_type type);
RET_CODE 	udisk_get_curdirinfo(mp_type type, UINT16 *dirnum, UINT16 *filenum); 
RET_CODE 	udisk_get_curdirname(mp_type type, char *name);
RET_CODE 	udisk_get_curdirpath(mp_type type, char *path);
//UINT8		udisk_load_playlist(char *dir_name, mp_type type, playlist_format format);
//RET_CODE	udisk_save_playlist(mp_type type, UINT8 idx, playlist_format format);	
//RET_CODE	udisk_set_playlist(mp_type type, UINT8 idx);
RET_CODE 	udisk_jumpdir(mp_type type, char* path, int* idx);
RET_CODE 	udisk_register_flter_name(char *name);


RET_CODE 	getfile(mp_type type, UINT16 idx, p_file_info pinfo);
RET_CODE	sortfile(mp_type type, sort_type mode);
RET_CODE 	file_getinfo(file_type type, UINT16 idx, UINT32* info);
//RET_CODE 	file_rename(mp_type type, UINT16 idx, const char *name);
//RET_CODE 	file_del(mp_type type, UINT16 idx);
RET_CODE 	file_get_temp_playlist_info(file_type type, UINT16 idx, UINT32* info);
int			filelist_findidx_byname(const char *path);
RET_CODE	filelist_active_temp_playlist(mp_type type, loop_type mode);
RET_CODE	filelist_inactive_temp_playlist(mp_type type, loop_type mode);
int			filelist_get_next_classifiedfile_index(mp_type type, int current_idx);
int			filelist_get_previous_classifiedfile_index(mp_type type, int current_idx);
int			filelist_get_radom_classifiedfile_index(mp_type type, int current_idx);
int			filelist_get_current_classifiedfile_index(mp_type type);
int			filelist_get_current_classifiedfile_count(mp_type type);
int			filelist_calibrate_current_classifiedfile_count(mp_type type, int index);
int			filelist_write_current_classifiedfile_count(mp_type type, int count);
int			filelist_get_classifiedfile_number(mp_type type);



UINT8 		playlist_create(mp_type type, const char *name);
RET_CODE 	playlist_destroy(mp_type type, UINT16 order);
RET_CODE 	playlist_addfile(mp_type type, UINT16 idx);
RET_CODE 	playlist_addall(mp_type type);
RET_CODE 	playlist_adddir(mp_type type, UINT16 idx);
RET_CODE 	playlist_delfile(mp_type type, UINT16 idx);
RET_CODE 	playlist_getlistinfo(mp_type type, p_playlist_info plistinfo);
RET_CODE 	playlist_setlistinfo(mp_type type, p_playlist_info plistinfo);
RET_CODE 	playlist_getfile(mp_type type, UINT16 idx, p_file_info pinfo);
RET_CODE 	playlist_getfileinfo(file_type type, UINT16 idx, UINT32 *info);
RET_CODE 	playlist_sort(mp_type type, sort_type mode);
UINT16 		playlist_getprevfileidx(mp_type type);
UINT16 		playlist_getnextfileidx(mp_type type);
RET_CODE 	playlist_batchdelfile(mp_type type, UINT32 *idx_array, UINT32 idx_array_size);
int			playlist_findidx_byname(mp_type type, const char * path);
RET_CODE	playlist_savetodisk(mp_type type);
RET_CODE	playlist_readfromdisk(mp_type type);



RET_CODE 	file_play(UINT16 idx, file_type type, UINT8 fromPL, UINT8 mode_rotate);
RET_CODE 	file_picture_thum(UINT16 idx, file_type type, RECT rect_info);
RET_CODE 	file_picture_preview(UINT16 idx, file_type type, RECT rect_info);
RET_CODE 	file_picture_previewPL(UINT16 idx, file_type type, RECT rect_info);
RET_CODE 	file_pause(file_type type);
RET_CODE 	file_resume(file_type type);
RET_CODE 	file_jump(file_type type, int time);
RET_CODE 	file_stop(file_type type);
//RET_CODE 	file_effect(file_type type, UINT32 *param);
RET_CODE 	getplayinfo_music(file_type type, p_playinfo_music info);
RET_CODE 	file_play_bypath(file_type type, char* path, UINT8 mode_rotate);
RET_CODE 	file_play_slow(file_type type);



/* 
//This API we don't use now
int get_current_image_index();
int get_current_image_list_size();
int get_next_image_index();
int get_pre_image_index();
void clear_cur_image_count();
int get_current_image_index();
void write_cur_image_count(int count);
void set_cur_image_count(int index);
*/

#endif //__LIB_MP_H__
